package a2022.a20221124;

/**
 * @author lenovo
 * @date 2022/11/24
 */
public class a {
    public static void main(String[] args) {
        System.out.println(numSubarrayBoundedMax(
                new int[]{73,55,36,5,55,14,9,7,72,52},
        32,
        69
));

    }

//    public static int numSubarrayBoundedMax(int[] nums, int left, int right) {
//        List<Integer> list = new ArrayList<>();
//        int length = nums.length;
//        int num = 0;
//        for (int i = 0; i < length; i++) {
//            if (nums[i] > right) {
//                list.add(num == 0 ? i : i - num);
//                num = i + 1;
//            }
//        }
//        if (num < length) list.add(num == 0 ? length - 1 : length - num);
//        num = 0;
//        for (int i = 0; i < list.size(); i++) {
//            int product = list.get(i) != 0 ? 1 : 0;//乘积
//            for (int j = 1; j <= list.get(i); j++) {
//                product = product * j;
//            }
//            num += product;
//        }
//        return num;
//    }

    public static int numSubarrayBoundedMax(int[] nums, int left, int right) {
        int res = 0, last2 = -1, last1 = -1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] >= left && nums[i] <= right) {
                last1 = i;
            } else if (nums[i] > right) {
                last2 = i;
                last1 = -1;
            }
            if (last1 != -1) {
                res += last1 - last2;
            }
        }
        return res;
    }

}
